<?php

namespace app\common\model;

use think\Model;

class UserVideo extends Model
{
    // 表名
    protected $name = 'user_video';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'expiretime_text'
    ];

    public function getExpiretimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expiretime']) ? $data['expiretime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function collection()
    {
        return $this->belongsTo('VideoCollection', 'collection_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}